
<template>
  <div class="officalItem flex1">
    <img class="listCover" :src="listItem.coverImgUrl|| cover" @click="checkAll(listId)" alt />
    <div class="right">
      <slot name="header"></slot>
      <ul>
        <li class="listRows flex2" v-for="(v,i) in songList" :key="v.id" @click="handleRowClick" @dblclick="handleDbClick(listId ,v.id ,i)">
          <div class="index flex3" :class="{'topThree':i < 3 }">{{i+1}}</div>
          <div class="musicName txt1">{{v.name}}</div>
          <div class="singer">{{v.ar[0].name}}</div>
        </li>
      </ul>
      <div class="checkAll flex2" @click="checkAll(listId)" v-if="isShowCheckAll">
        查看全部
        <i class="iconfont icon-arrow-right-bold"></i>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'songTable',
  props: {
    listItem: {
      type: Object,
      default() {
        return {}
      }
    },
    cover: {
      type: String,
      default: ''
    },
    listId: { type: [Number, String], default: '' },
    isShowCheckAll: {
      type: Boolean,
      default: true
    }
  },
  computed: {
    songList() {
      if (this.listItem.songs) {
        return this.listItem.songs.slice(0, 10)
      }
      if (this.listItem.topSongs) {
        return this.listItem.isOpen ? this.listItem.topSongs : this.listItem.topSongs.slice(0, 10)
      }
      return []
    }
  },
  methods: {
    checkAll(id) {
      if (this.listItem.coverImgUrl) {
        return
      }
      this.$emit('checkAll', id)
    },
    handleDbClick(listId, id, i) {
      this.$emit('handleDbClick', listId, id, i)
    },
    handleRowClick(e) {
      let path = null
      if (e.target.classList.contains('listRows')) {
        path = e.target
      } else {
        path = e.target.parentNode
      }
      this.$emit('handleRowClick', path)
    }
  }
}
</script>

<style scoped >
.officalItem {
  margin: 20px 0 50px;
}
.listCover {
  margin-right: 20px;
  width: 150px;
  height: 150px;
  border-radius: 10px;
  cursor: pointer;
}
.right {
  font-size: 12px;
  width: calc(100% - 200px);
}
ul {
  color: rgb(153, 153, 153);
  font-size: 12px;
  border-radius: 5px;
  overflow: hidden;
}
.listRows {
  position: relative;
  width: 100%;
  height: 30px;
}
.listRows:nth-child(odd) {
  background-color: #f9f9f9;
}
.listRows:hover {
  color: rgb(153, 153, 153);
  background-color: #f4f4f4;
}
.musicName {
  color: rgb(31, 31, 31);
  width: 80%;
}
.index {
  width: 30px;
  text-align: center;
}
.index i {
  font-size: 12px;
}
/* .topThree {
  color: rebeccapurple;
} */
.singer {
  position: absolute;
  right: 10px;
  text-align: right;
}
.checkAll {
  width: 100px;
  height: 30px;
  color: rgb(134, 134, 134);
  cursor: pointer;
}
.checkAll i {
  font-size: 12px;
}
.listRows.selectRow {
  color: #fff !important;
  background-color: var(--purple);
}
.selectRow .musicName {
  color: #fff;
}
</style>
